package com.hqyj.javaGraduation.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
public class MyEmail {

    @Autowired
    private JavaMailSenderImpl mailSender;

    public HashMap<String,Object> sendMail(String email,String content){
        HashMap<String,Object> hashMap = new HashMap();
            try{
                SimpleMailMessage message = new SimpleMailMessage();
                message.setSubject("测试邮件主题");//设置邮件的主题
                message.setText(content);   //设置邮件的正文
                message.setFrom("2748893788@qq.com"); //从哪里发
                message.setTo(email); //发向哪里
                mailSender.send(message);
                hashMap.put("info","发送成功");
            }catch (Exception e){
                hashMap.put("info","发送失败");
                e.printStackTrace();
            }
        return hashMap;
    }
}
